/**
 * @author Administrator
 */
package com.mijie.query;

import static com.mijie.homi.DSL.List4dsl.*;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.sql.DataSource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.test.JSONAssert;

import org.apache.log4j.Logger;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;

import com.chenlb.mmseg4j.example.Complex;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.mijie.fentsi.LuceneSearch;
import com.mijie.fentsi.MMsegFentsicyi;
import com.mijie.fentsi.WordsLibController;
import com.mijie.fentsi.exportTopic;
import com.mijie.fentsi.fentsiCa22;
import com.mijie.fentsi.fentsiController;
import com.mijie.fentsi.fentsiOr;
import com.mijie.fentsi.renvaEventC;
import com.mijie.homi.search.util.DbNdsController;
import com.mijie.homi.search.util.Dbcontroller;
import com.mijie.homi.search.util.fileC0;
import com.mijie.homi.search.util.god;
import com.mijie.homi.search.util.listUtil;
import com.mijie.homi.search.util.securyInt;
import com.mijie.homi.search.util.strUtil;
import com.mijie.homi.search.util.timeTester;
import com.mijie.homi.search.util.tryX;


@SuppressWarnings({"unchecked","unused","static-access"})
 
public class fulltxtControllor extends LuceneIndex {

	protected String renvaAll;
	protected String eventAll;
	fulltxtControllorExtSearch fullsearch;
	public boolean isuseExtWord;
	public static MMsegFentsicyi MMsegFentsicyi;
	public static boolean wordlibcache = true;

	public fulltxtControllor() {
		super(0);
		fullsearch = new fulltxtControllorExtSearch();
	}

	public fulltxtControllor(int none) {
		super(0);
	}

	/**
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws InterruptedException {

		// insert into mood(id,content,renva,event,cinsyv)values(123,
		// #{content},Rv1, ev1,@cinsiv)

		// System.out.println(sql);
		// if(true)return;

		// c.indexAll();

		// c.writeToIndexSingle(" 二胡胡胡");

		// Thread.sleep(15000);
		timeTester t = new timeTester("cb1");
		// testIniFentsilibAll();// 1622毫秒

		testSearch();

		t.printUseTime();

		// testgetMoodnamesByids();
		System.out.println("--f");
		// while(true)
		// {
		// Thread.sleep(15000000);
		// }

	}

	private static void testIniFentsilibAll() {
		fentsiController fentsiController_cbb = new fentsiController();
		fentsiController_cbb.iniFentsiWordlibFromdb();

	}

	static Logger logger = Logger.getLogger("full_cb20");
public	static Logger logger_for_match_debug = Logger.getLogger("logger_for_match_debug");

	private static void testSearch() {
		String sx = "开心@老婆，你是我见过最可爱的人！” “么么～老公，我就喜欢你这种没见过世面的……";
		sx = "伤心@想有个女闺蜜，很好很好的闺蜜，对我好，我也对她好的那种，很渴望有这么一个人";
		// sx="伤心@很渴望有这么一个人";
		// sx="伤心@^_^我们分手快10年了";
		sx = "伤心@啊啊，家人反对我跟现在这个女朋友在一起";
		sx = "伤心@和男朋友整天吵架，他怎么可以那么抠，什么东西都不舍得给我买";
		// sx="愤怒@超级讨厌，人怎么这样啊";
		sx = "愤怒@烦心的啊，爱上一个不在乎自己的人，她周围的好朋友有些跟我还有些瓜葛，我到底追不追呢";
		sx = "纠结@犇犇";
		sx="纠结@啊啊，家人反对我跟现在这个女朋友在一起";
		sx="纠结@钱钱钱,没有钱怎么办了.";
		sx = "伤心@和女朋友吵架了.";
		sx="开心@^_^";
	 	
		
		//for test dweiu multi renva and sicin
		//异地恋  fedwei tsogo ,renva: tonsi,lyengai tonsye
		/*
		ND renva IN (
				'长辈关系',
				'同学关系',
				'夫妻关系',
				'恋爱男女',
				'同事关系'
			)
			AND EVENT IN (
				'0064_拒绝',
				'0014_错过',
				'0001_追求',
				'0007_异地恋',
				'0017_反对'*/
		sx="纠结@班长 女人 女朋友  喜欢yg女生  公司yg女的 错过  同yg学校  父母hen不喜欢";
		sx="伤心@";
		sx="开心@哎哟不错哦";
		sx="纠结@我冤枉啊啊啊啊";
	//	sx="纠结@啊啊啊啊啊啊啊啊啊啊啊呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜";
		
		fulltxtControllor c = new fulltxtControllor();
		c.wordlibcache = true;
		c.exceptUid = 585115;
		c.search(sx);
		// if(true)return;
		// c.search(sx);
		// dbc.close();
		logger_for_match_debug.info(" 分词:" + c.s_fentsi);
		logger_for_match_debug.info(" 过滤FISRT:" + c.s_fentsi_filtedFirst);
		logger_for_match_debug.info(" 过滤FINALLY:" + c.s_fentsi_filtedFinaly);
		logger_for_match_debug.info(" fentsi by ik" + c.s_fentsi_byIK);
		String s_nbs = " fentsi by mmseg" + c.s_fentsi_byMMseg;
		logger.info(s_nbs);
		logger_for_match_debug.info(s_nbs);
		String cywejon = c.fentsi_filted_ext_cywejon.replace('>', '+')
				.replace('<', '-');
		logger_for_match_debug.info(" 权重过滤:" + cywejon);
		logger_for_match_debug.info(" 同义扩展:" + c.s_fentsi_filted_ext);
		logger_for_match_debug.info(" 人物关系:" + c.renvas_strfmt);
		logger_for_match_debug.info(" 事件:" + c.events_strfmt);
		logger_for_match_debug.info(" 情绪:" + c.cinsyv_debug);
		logger_for_match_debug.info(" 情绪扩展:" + c.cinsyv_ext);
		logger_for_match_debug.info(c.searchResult);

	}

	private static void testgetMoodnamesByids() {
		String ids = "1,2,4";
		fulltxtControllor c = new fulltxtControllor();
		String names = c.getMoodnamesByids(ids);
		System.out.println(names);

	}

	public String s_fentsi;
	public String s_fentsi_filted;
	public String events_strfmt;
	public String renvas_strfmt;
	public String s_fentsi_filted_ext;
	public String cinsyv_ext;
	public String cinsyv_debug;
	fentsiOr fentsiControllor;
	public String fentsi_filted_ext_cywejon = "";
	public String s_fentsi_filtedFirst = "";
	public String s_fentsi_filtedFinaly = "";

	public static fentsiController fentsiController_cbb;
	private boolean isUseWordlibCatch = false;
	/**
	 * cbc
	 */
	private boolean eventIsCyita = false;
	public String s_fentsi_byMMseg;
	public String s_fentsi_byIK;
	String renvalist_sqlParamfmt;
	private List<Map> renvas_li;
	private String[] str_arrFmt;
	/**
	 * 
	 "id": "354308", "content": "因为 爱情 家庭 孩子 自由 老公 出轨 吵架 打架", "匹配度": "33.53%",
	 * "g": "1", "pipeidu": 33.52922, "情绪分类": "负面", "人物关系":"[{\"num\":2,\"name\":\"夫妻关系\"},{\"num\":1,\"name\":\"恋爱男女\"},{\"num\":1,\"name\":\"孩子教育\"}]"
	 * , "事件":"[{\"num\":1,\"event\":\"0011_第三者\"},{\"num\":1,\"event\":\"0005_吵架\"},{\"num\":1,\"event\":\"0006_打架\"},{\"num\":1,\"event\":\"0001_追求\"}]"
	 * , "来源": "心情库", "filt": "爱情 家庭 孩子 自由 老公 出轨 吵架 打架", "filt_ini":
	 * "爱情 家庭 孩子 自由 老公 出轨 吵架 打架"
	 */
	public List searchResult_li=new ArrayList<Object>();

	/**
	 * select content, match(content) against('婚姻 爱情 坟墓 幸福' IN BOOLEAN MODE ) as
	 * score from mood4full where match(content) against('婚姻 爱情 坟墓 幸福' IN
	 * BOOLEAN MODE ) order by score desc
	 * 
	 * @param sx
	 * @author attilax 1466519819@qq.com
	 * @since ca25
	 */

	public void search(String sx) {

		ini_fentsiControllerX();

		System.out.println(renvaEventC.map4renvaDweiu);

		LuceneIndex lic = new LuceneIndex(0);

		String[] sxArr = sx.split("@");
		String sincin = sxArr[0];
	 
		//o19
		String str =securyInt.getString(  sxArr,1,"");
		if(str.length()==0)
			str=sincin;
		LuceneSearch ls = new LuceneSearch();
		ls.fentsiCa22_new = new fentsiCa22();

		// if (!isUseWordlibCatch) {// default
		// if (fentsiController_cbb == null) {

		// }

		// } else {
		// fentsiController_cbb = new fentsiController();
		// fentsiController_cbb.iniFentsiWordlibFromdb();
		// }

		// tt1.printUseTime();

		timeTester tt2 = new timeTester(" fentsi by ik");
		fentsiController_cbb.isLoadDic = true;
		s_fentsi = fentsiController_cbb.fentsiByDBwordlib(str);
		tt2.printUseTime();
		this.fentsi_mmseg_time = tt2.pasttime;

		// cbg
		s_fentsi_byIK = s_fentsi;

		// /cbg

		// cbc
		timeTester tt3 = new timeTester(" fentsi by mmseg");
		List<String> fentsiedStrByMMseg_list;
		// = new Complex().fentsi(str);

		fentsiedStrByMMseg_list = MMsegFentsicyi.fentsi(str);// cbg

		tt3.printUseTime();

		timeTester tt4 = new timeTester(" count fentsi cywejon");
		List<String> li_finaly = countCywejon(
				fentsiController_cbb.s_fentsied_listfmt,
				fentsiedStrByMMseg_list);
		s_fentsi = listUtil.toString(li_finaly, "|");
		tt4.printUseTime();
		logger_for_match_debug.info(" 分词:" +  s_fentsi);

		// cbg
		s_fentsi_byMMseg = listUtil.toString(fentsiedStrByMMseg_list, " | ");

		// /cbg

		// //cbc

		renvaEventC renvaEventCca22 = fentsiController_cbb.renvaEventCon;
		// cb9 only byaocin
		if (s_fentsi.length() == 0) {
			List<Map> li = getByaocinOnlyMatch(str);
		 	this.searchResult_li=li;
			String s = JSONArray.fromObject(li).toString(2);
			// System.out.println(s);
			searchResult = s;// cbg
			return;
		}
		// //
		timeTester tt5 = new timeTester(" filt ext get evetn renva");
		fentsiControllor = fentsiCca22;

		ls.fentsiCa22_new.renvaEventKws = (List<String>) get_renvaEventKws();

		fentsiCa22 fentsiCa22_c20 = new fentsiCa22();
		s_fentsi_filtedFirst = fentsiCa22_c20.filtBydb(s_fentsi);
		// cb4
		if (s_fentsi_filtedFirst.trim().split(" ").length <= 0) {
			s_fentsi_filtedFinaly = s_fentsi;
			// s_fentsi_filted="未来 哪里";
		} else
			s_fentsi_filtedFinaly = s_fentsi_filtedFirst;

		s_fentsi_filted_ext = extWord(s_fentsi_filtedFinaly);
		System.out.println(s_fentsi);
		System.out.println(s_fentsi_filted);
		System.out.println(s_fentsi_filted_ext);
		
		logger_for_match_debug.info(" 过滤FISRT:" + s_fentsi_filtedFirst);
		logger_for_match_debug.info(" 过滤FINALLY:" + s_fentsi_filtedFinaly);

		// chagge keyword a|b >> a b .
		String keyword = s_fentsi_filtedFinaly;
		if (this.isuseExtWord)
			keyword = (String) s_fentsi_filted_ext;
		keyword = keyword.replaceAll("\\|", " ");
		keyword = keyword.replaceAll("  ", " ");
		keyword = keyword.trim();

		String[] keywArr = keyword.split(" ");
		this.str_arrFmt = keywArr;
		// cb4
		fentsi_filted_ext_cywejon = getCywejonMysqlFormat(keywArr);
		String cywejon =  fentsi_filted_ext_cywejon.replace('>', '+')
		.replace('<', '-');
logger_for_match_debug.info(" 权重过滤:" + cywejon);

		// get type
		List<Map> renvaResult = renvaEventCca22.getRenvasByKWnDweiuNKW2(
				keywArr, str);
		// cbb arjy kw
		// if(renvaResult.size()==0)
		renvalist_sqlParamfmt = getRenva_SqlParamfmt(renvaResult);
		this.renvas_strfmt = renvalist_sqlParamfmt;
		lic.renvaList = renvaResult;
		this.renvas_li = renvaResult;

		// get event
		// lic.getEventX(keywArr);

		renvaEventC rc = renvaEventCca22;
		rc.oritxt = str;
		//@SuppressWarnings("unused")
		List liEvent = rc.getEventsFromDBlib(keywArr, lic.renvaList);
		this.events_li = liEvent;
		List<Map> lievents = liEvent;

		// cbc
		if (isCyita(liEvent)) {
			eventIsCyita = true;
		}else
			eventIsCyita = false;

		// //cbcc

		// /get cinsyv
		String events = getEvents_SqlParamfmt(lievents);
		this.events_strfmt = events;
		this.events_sqlParamFmt = events;
		String cinsyv = sincinController.getcinsyv(sincin);
		this.cinsyv_debug = cinsyv;
		cinsyv_ext = cinsyv_ext_sqlfmt(cinsyv);
		tt5.printUseTime();
		
		
		logger_for_match_debug.info(" 同义扩展:" + s_fentsi_filted_ext);
		logger_for_match_debug.info(" 人物关系:" + renvas_strfmt);
		logger_for_match_debug.info(" 事件:" + events_strfmt);
		logger_for_match_debug.info(" 情绪:" + cinsyv_debug);
		logger_for_match_debug.info(" 情绪扩展:" + cinsyv_ext);

		// cbg
		List<Map> li = (List<Map>) getQuery();
		if (li.size() == 0) {
			List<Map> licbg = new ArrayList<Map>();
			Map mp = new HashMap<String, String>();
			mp.put("event", "_其他");
			licbg.add(mp);
			events_li = licbg;
			li = (List<Map>) getQuery();
			if (li.size() == 0) {
				renvas_li = new ArrayList<Map>();
				events_li = new ArrayList<Map>();
				li = (List<Map>) getQuery();
				if (li.size() == 0) {
//o12 delte 
//					检索不到结果，随机返回结果，删除这部分代码
//					10、第一层：在指定人物事件分类下检索
//					第二层：在其他事件分类下检索
//					第三层：在全部数据检索
//					第四层：随机返回一批跟用户的心情属性一致的心情，相似度为0
//					List<Map> licbg2 = getTonSincinMsg(str);
//					String s = JSONArray.fromObject(licbg2).toString(2);
//					// System.out.println(s);
//					searchResult = s;// cbg
//					li = licbg2;
 //					return;
				}
			}

		}
		// /cbg

		List li_order = listUtil.orderByValueFloat(li, "pipeidu");
	//	List li_order_byDsl=from(li).orderBy("pipeidu").desc();
		this.searchResult_li = li_order;
		String eventStrformat = JSONArray.fromObject(li_order).toString(2);
		// return li;
		// System.out.println(sql);
		// System.out.println(eventStrformat);
		searchResult = eventStrformat;
		logger_for_match_debug.info("---searchResult::"+searchResult);

	}

	/**
	 * ik and mmseg
	 */
	protected static void ini_fentsiController() {

		WordsLibController.syvtsiLib = null;
		WordsLibController.RenvaEventKws = null;

		timeTester tt1 = new timeTester("ini word db");
		Dbcontroller dbc = new DbNdsController();
		fentsiController fentsiControllerX = new fentsiController();
		fentsiControllerX.dbc20 = dbc;
		fentsiControllerX.iniFentsiWordlibFromdb();
		tt1.printUseTime();
		ini_words_time = tt1.pasttime;
		fentsiController_cbb = fentsiControllerX;
		logger.info(" ini word db ,past time:" + tt1.pasttime);

		// cbg
		timeTester tt1a = new timeTester("ini mmseg tree by worddb list");
		WordsLibController.words = fentsiControllerX.words_include_renvaEventKw;
		MMsegFentsicyi MMsegFentsicyi2 = new MMsegFentsicyi(
				fentsiControllerX.words_include_renvaEventKw);
		MMsegFentsicyi = MMsegFentsicyi2;
		tt1a.printUseTime();
		logger.info("add to mmseg tree ,past time:" + tt1a.pasttime);

		// /cbg

		dbc.close();

	}

	/**
	 * ini once
	 */
	public static void ini_fentsiControllerX() {

		if (wordlibcache) {
			if (fentsiController_cbb == null) {
				ini_fentsiController();
			}
		}

		if (wordlibcache == false) {
			ini_fentsiController();

		}

	}

	private List<Map> getTonSincinMsg(String sincin) {
		timeTester t = new timeTester("getTonSincinMsg");
		String sql = "select * from mood where char_length(content)>3    order by id desc limit 100";
		// sql = sql.replaceAll("@str", str.trim());
		DbNdsController dbcb9 = new DbNdsController();
		logger.info(sql);
		ResultSet rs = dbcb9.getrs(sql);
		List<Map> li = new ArrayList<Map>();
		try {
			while (rs.next()) {
				Map mp = new LinkedHashMap<String, String>();
				mp.put("id", rs.getString("id"));
				mp.put("content", rs.getString("content"));
				mp.put("匹配度", "0%");
				// "content": "真的 很 害怕 有 一天 会有 另外 一个人 出现 取代 了 我 在 你 心 中的 位置 ",
				// "匹配度": "50.00%"
				li.add(mp);
			}
		} catch (SQLException e) {

			e.printStackTrace();
			throw new RuntimeException(e);
		}
		dbcb9.close();
		t.printUseTime();
		logger.info(" getTonSincinMsg time:" + t.pasttime);

		return li;
	}

	String events_sqlParamFmt;
	public Dbcontroller dbc_tbn;

	/**
	 * cbg
	 * 
	 * @param renvalist_sqlParamfmt
	 *            events_sqlParamFmt str_arrFmt renvas_li events_li ,exceptUid
	 * 
	 * @return
	 */
//	@SuppressWarnings("unchecked")
	private Object getQuery() {
		timeTester tt6 = new timeTester("  exec sql");
		// select id,content from mood where match(keyword) against('+恋爱+分手' IN
		// BOOLEAN MODE ) ORDER BY id desc  order by score desc
		String match = " match(content)  against('"
				+ fentsi_filted_ext_cywejon + "'  IN BOOLEAN MODE  )";
		String sql = "select *,@match as score from mood4full "
				+ " where   @match @renva_part_sql  @event_part_sql and cinsyv in(@cinsyv) "
				+ "  and  char_length (content)>1 @onlyPrblm order by score desc limit 200";
		sql = sql.replaceAll("@match", match);

		// cbg
		String renva_part_sql = " and renva in(@renva) ";
		if (renvas_li.size() == 0) {
			renva_part_sql = "";
			sql = sql.replaceAll("@renva_part_sql", renva_part_sql);
		} else {
			renvalist_sqlParamfmt = getRenva_SqlParamfmt(renvas_li);
			sql = sql.replaceAll("@renva_part_sql", renva_part_sql);
			sql = sql.replaceAll("@renva", renvalist_sqlParamfmt);
		}
		String event_part_sql = " and event in(@event) ";
		if (events_li.size() == 0) {
			event_part_sql = "";
			sql = sql.replaceAll("@event_part_sql", event_part_sql);
		} else {
			events_sqlParamFmt = getEvents_SqlParamfmt(this.events_li);
			sql = sql.replaceAll("@event_part_sql", event_part_sql);
			sql = sql.replaceAll("@event", events_sqlParamFmt);
		}

		//o19 only prblm
		if(this.onlyPrblm)
			sql = sql.replaceAll("@onlyPrblm", " and fromx='problemlib' ");
		else
			sql = sql.replaceAll("@onlyPrblm", "  ");
		
		if (str_arrFmt.length == 0) {

		}

		// //cbg

		sql = sql.replaceAll("@cinsyv", cinsyv_ext);
		System.out.println(sql);
		logger.info(sql);
		logger_for_match_debug.info(sql);
		Set<String> setDeduli = new HashSet<String>();
		Set<String> sincinIds_set = new HashSet<String>();
		Set<String> prblmIds_set = new HashSet<String>();
		List<Map> li = new ArrayList<Map>();

		Dbcontroller dbc = new DbNdsController();
		ResultSet rs = dbc.getrs(sql);
		tt6.printUseTime();
		this.exe_query_sql_time = tt6.pasttime;
		timeTester tt7 = new timeTester("  show result");
		try {
			while (rs.next()) {

				// 首先使用ISO-8859-1字符集将name解码为字节序列并将结果存储新的字节数组中。
				// 然后使用GB2312字符集解码指定的字节数组
				// name = new String(name.getBytes("ISO-8859-1"),"GB2312");
				String mid = rs.getString("mid");
				if (mid.equals("419399"))
					System.out.println(mid);

				// 输出结果
				String txt = rs.getString("content");
				String txt_filt = getFilted(txt);
				Map mp = new LinkedHashMap<String, String>();

				// String mid = rs.getString("mid");
				mp.put("id", mid);
				// mp.put("userId", rs.getString("userId"));

				// mp.put("moodname", rs.getString("name"));
				mp.put("content", txt);

				// renva pipeidu
				String renvas = rs.getString("renvaAll");
				Float renvaPipeidu = getRenvaPipeidu(renvas_li, renvas);
				Float renvaPipeidu_fesyeo = getRenvaPipeidu_MymsgDivLibmsg(
						renvas_li, renvas);

				// event pipeidu
				String events_jsonfmt = rs.getString("eventAll");
				Float eventPipeidu = getEventPipeidu(events_li, events_jsonfmt);
				Float eventPipeidu_fesyo = getEventPipeidu_MymsgDivLibmsg(
						events_li, events_jsonfmt);
				// cbc
				if (eventIsCyita) {
					eventPipeidu = 0f;
					eventPipeidu_fesyo = 0f;

					wordPercent = 75f;
				}else
				{//o12 restorte byefenhao
					wordPercent = 50f;
				}
				// ///

				// word pinpeidu
				String[] txt_filt_arr = txt_filt.split(" ");
				Float word_pipeidu_libDivMymsg = getWord_pipeidu_libDivMymsg(
						txt_filt_arr, str_arrFmt);
				Float word_pipeidu__fesyo_MymsgDivLibmsg = getWord_pipeidu_MymsgDivLibmsg(
						str_arrFmt, txt_filt_arr);

				// cout pipeidu
				String string = rs.getString("score");
				//
				// Float f = Float.parseFloat(string);
				//			
				// Float f1 = (f / txt_filt_arr.length) * 34 + 66;
				// if (f1 > 100)
				// f1 = 100f;
				Float jensyeoPipeidu = 0 + renvaPipeidu + eventPipeidu
						+ word_pipeidu_libDivMymsg;
				Float fesyoPipeidu = 0 + renvaPipeidu_fesyeo
						+ eventPipeidu_fesyo
						+ word_pipeidu__fesyo_MymsgDivLibmsg;
				Float jenfesyoJyaosyaoj;
				if (jensyeoPipeidu > fesyoPipeidu)
					jenfesyoJyaosyaoj = fesyoPipeidu;
				else
					jenfesyoJyaosyaoj = jensyeoPipeidu;
				float abs = Math.abs(jensyeoPipeidu - fesyoPipeidu);
				Float finalPipeidu = jenfesyoJyaosyaoj + (1 - abs / 100)
						* (abs / 2);
				if (finalPipeidu > 100)
					finalPipeidu = 100f;

				DecimalFormat df = new DecimalFormat("#.00");
				String f2_str = df.format(finalPipeidu) + "%";
				mp.put("匹配度", f2_str);
				mp.put("g", string);
				// //

				mp.put("pipeidu", finalPipeidu);

				// nbp
				String pipeiduX = "人物匹配度:" + renvaPipeidu.toString() + " 反向:"
						+ renvaPipeidu_fesyeo.toString();
				pipeiduX += " 事件匹配度：" + eventPipeidu.toString() + "  事件反向:"
						+ eventPipeidu_fesyo.toString();
				pipeiduX += " 关键字匹配:" + word_pipeidu_libDivMymsg.toString()
						+ " 反向:"
						+ word_pipeidu__fesyo_MymsgDivLibmsg.toString();
				logger_for_match_debug.info(pipeiduX);
				mp.put("pipeiduX", pipeiduX);

				mp.put("情绪分类", rs.getString("cinsyv"));

				mp.put("人物关系", renvas);

				mp.put("事件", events_jsonfmt);

				String fromx = rs.getString("fromx");
				if (fromx.equals(god.sincinlib))
					mp.put("来源", "心情库");
				else
					mp.put("来源", "问题库");
				mp.put("fromx", fromx);
				mp.put("filt", txt_filt);
				mp.put("filt_ini", fentsi_filted_per_dbline_ini);

				// m.id,m.userId,mood,moodInfo.name,m.content

				if (!setDeduli.contains(mid)) {

					li.add(mp);
					setDeduli.add(mid);
					// cb24 except uid
					if (this.exceptUid > 0) {
						if (fromSincinLib(fromx))
							sincinIds_set.add(mid);
						else
							prblmIds_set.add(mid);
					}
					// /
				}

			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			dbc.close();
		}
		
	//	listUtil.orderByValueFloat(li, "pipeidu");

		// tbn except uid
		List<Map> li_tbn = except_uidByMids(sincinIds_set, prblmIds_set, li);

		// /
		tt7.printUseTime();
		return li_tbn;
	}

	/**
	 * 排除本人
	 * @param sincinIdsSet
	 * @param prblmIdsSet
	 * @param li
	 * @return
	 */
	private List<Map> except_uidByMids(Set<String> sincinIdsSet,
			Set<String> prblmIdsSet, List<Map> li) {
		List<Map> li_r = new ArrayList<Map>();
		Dbcontroller dbc = new DbNdsController();
		this.dbc_tbn = dbc;
		Set<String> will_excep_set = new HashSet<String>();
		if (sincinIdsSet.size() > 0) {
			String sincinIds = listUtil.toString(sincinIdsSet);
			Set<String> sincinIds_will_except = get_sincinIds_will_except(
					sincinIds, this.exceptUid);
			sincinIds_will_except.size();
			will_excep_set.addAll(sincinIds_will_except);

		}
		if (prblmIdsSet.size() > 0) {
			String sincinIds = listUtil.toString(prblmIdsSet);
			Set<String> sincinIds_will_except = get_prblmIds_will_except(
					sincinIds, this.exceptUid);
			will_excep_set.addAll(sincinIds_will_except);
		}

		// log
		String vals = listUtil.getVals(li, "id");
		logger.info(" ids ori " + vals);
		logger
				.info(" ids will_excep_set "
						+ listUtil.toString(will_excep_set));
		// /
		Set<String> set = new HashSet<String>();
		set.addAll(will_excep_set);
		for (Map m : li) {
			String id = (String) m.get("id");
			if (id.trim().equals("550519"))
				System.out.println("");
			if (!will_excep_set.contains(id.trim()))
				li_r.add(m);
		}
		dbc.close();
		return li_r;
	}

	public Set<String> get_sincinIds_will_except(String sincinIds,
			int exceptUid2) {

		String sql = "	select id from  mood where id   in (" + sincinIds
				+ ") and  userid= " + String.valueOf(exceptUid2);
		logger.info(sql);
		String vals_str = dbc_tbn.vals_str(sql);
		return listUtil.toSet_splitComma(vals_str);
	}

	private Set<String> get_prblmIds_will_except(String sincinIds,
			int exceptUid2) {

		String sql = "	select id from  topic where id   in (" + sincinIds
				+ ") and  author= " + String.valueOf(exceptUid2);
		logger.info(sql);
		String vals_str = dbc_tbn.vals_str(sql);
		return listUtil.toSet_splitComma(vals_str);
	}

	private boolean fromSincinLib(String fromx) {
		if (fromx.equals(god.sincinlib))
			return true;
		else

			return false;
	}

	private List<String> get_renvaEventKws() {
		List<String> li = new ArrayList<String>();
		// cbe
		List<String> renvaKws = fentsiController_cbb.renvaEventCon.renvaKws;
		for (String kw : renvaKws) {
			li.add(kw);
		}
		List<String> eventKws = fentsiController_cbb.renvaEventCon.eventKws;
		for (String kw : eventKws) {
			li.add(kw);
		}
		return li;
	}

	private boolean isCyita(List liEvent) {
		if (liEvent.size() > 1)
			return false;
		Map mp = (Map) liEvent.get(0);
		String event = (String) mp.get("event");
		if (event.equals("_其他"))
			return true;

		return false;
	}

	private List<String> countCywejon(List<String> sFentsiedListfmt,
			List<String> fentsiedStrByMMsegList) {
		Float f1 = getCywejonSyishorSum(sFentsiedListfmt);
		Float f2 = getCywejonSyishorSum(fentsiedStrByMMsegList);
		if (f1 >= f2)
			return sFentsiedListfmt;
		else

			return fentsiedStrByMMsegList;
		// return null;
	}

	private List<Map> getByaocinOnlyMatch(String str) {
		timeTester t = new timeTester("getByaocinOnlyMatch");
		
		String pipeidu = "50%";
		boolean replaceerr = false;
		String sql = "select * from mood where LENGTH(content)<8 and LENGTH(content)>0 and content like '@str%' order by id desc limit 50";
		try {
			sql = sql.replaceAll("@str", str.trim());
		} catch (Exception e) {
			// nbp if str =$ catch
			logger.warn(god.getTrace(e));
			sql = sql.replaceAll("@str", "^");
			replaceerr = true;
		}
		DbNdsController dbcb9 = new DbNdsController();
		ResultSet rs = dbcb9.getrs(sql);
		List<Map> li = new ArrayList<Map>();
		try {
			while (rs.next()) {
				Map mp = new LinkedHashMap<String, String>();
				mp.put("id", rs.getString("id"));
				mp.put("content", rs.getString("content"));
				mp.put("匹配度", "100%");
			//	mp.put("pipeidu", "100%");
				mp.put(strUtil.pipeidu,100);
				if (replaceerr)
					mp.put("匹配度", "50%");
				// "content": "真的 很 害怕 有 一天 会有 另外 一个人 出现 取代 了 我 在 你 心 中的 位置 ",
				// "匹配度": "50.00%"
				li.add(mp);
			}
		} catch (SQLException e) {

			e.printStackTrace();
			throw new RuntimeException(e);
		}
		dbcb9.close();
		t.printUseTime();
		logger.info("getByaocinOnlyMatch" + t.pasttime);
		return li;
	}

	public String searchResult;
	float wordPercent = 50f;

	private Float getWord_pipeidu_MymsgDivLibmsg(String[] keywArr,
			String[] txtFiltArr) {
		// mymsg set1
		Set<String> set1 = listUtil.toSet(keywArr);
		// libmsg set
		Set<String> set2 = listUtil.toSet(txtFiltArr);
		// Float exist_bilw= getEexist_bilwx(set1,set2);
		// Float pipeidu = exist_bilw * 30f;
		List<String> exist_word = getEexist_word(set1, set2);
		Float exist_word_syishor = getCywejonSyishorSum(exist_word);
		Float fenmu_CywejonSyishorSum = getCywejonSyishorSum(set2);

		Float pipeidu = exist_word_syishor / fenmu_CywejonSyishorSum
				* wordPercent;
		return pipeidu;
		// return pipeidu;

	}

	private Float getEventPipeidu_MymsgDivLibmsg(List liEvent,
			String eventsJsonfmt) {
		// mymsg set1
		Set<String> set1 = listUtil.toSet(liEvent, "event");
		// libmsg set
		Set<String> set2 = listUtil.toSetFromJsonArray(eventsJsonfmt, "event");
		Float exist_bilw = getEexist_bilwx(set1, set2);
		Float pipeidu = exist_bilw * evetnPercent;
		return pipeidu;
	}

	private Float getRenvaPipeidu_MymsgDivLibmsg(List<Map> renvaResult,
			String renvas) {

		// mymsg set1
		Set<String> set1 = listUtil.toSet(renvaResult, "name");
		// libmsg set
		Set<String> set2 = listUtil.toSetFromJsonArray(renvas, "name");
		Float exist_bilw = getEexist_bilwx(set1, set2);
		Float pipeidu = exist_bilw * evetnPercent;
		return pipeidu;
	}

	private Float getEexist_bilwx(Set<String> set1, Set<String> set2) {

		return getEexist_bilw(set2, set1);
	}

	private Float getWord_pipeidu_libDivMymsg(String[] txtFiltArr,
			String[] keywArr) {
		// CywejonMap
		// libmsg set1
		Set<String> set1 = listUtil.toSet(txtFiltArr);
		// mymsg set
		Set<String> set2 = listUtil.toSet(keywArr);
		List<String> exist_word = getEexist_word(set1, set2);
		Float exist_word_syishor = getCywejonSyishorSum(exist_word);
		Float fenmu_CywejonSyishorSum = getCywejonSyishorSum(set2);
		Float pipeidu = exist_word_syishor / fenmu_CywejonSyishorSum
				* wordPercent;
		return pipeidu;
	}

	private Float getCywejonSyishorSum(Set<String> set2) {
		List<String> li = listUtil.toList(set2);
		return getCywejonSyishorSum(li);
	}

	private Float getCywejonSyishorSum(List<String> existWord) {
		// getCywejonSet();
		Float n = 0f;
		for (String word : existWord) {
			String cyweonjonSyishor_str = (String) CywejonMap.get(word);
			if (cyweonjonSyishor_str == null)
				cyweonjonSyishor_str = "1";
			Float f = Float.parseFloat(cyweonjonSyishor_str);
			n = n + f;
		}

		return n;
	}

	private List<String> getEexist_word(Set<String> set1, Set<String> set2) {
		List<String> li = new ArrayList<String>();
		Iterator i = set1.iterator();// 先迭代出来

		while (i.hasNext()) {// 遍历
			String item = (String) i.next();
			if (set2.contains(item))
				li.add(item);
		}
		return li;
	}

	private Float getEexist_bilw(Set<String> set1, Set<String> set2) {
		int count = set1.size();
		int exist_num = 0;
		Iterator i = set2.iterator();// 先迭代出来

		while (i.hasNext()) {// 遍历
			String item = (String) i.next();
			if (set1.contains(item))
				exist_num++;
		}
		Float pipeidu = new Float(exist_num) / new Float(count);

		return pipeidu;
	}

	float evetnPercent = 25;

	private Float getEventPipeidu(List<Map> liEvent, String eventsJsonfmt) {
		if (liEvent.size() == 0)
			return 0f;
		Set set = new HashSet<String>();
		for (Map mp : liEvent) {
			set.add(mp.get("event"));
		}
		int count = set.size();

		Set set2 = listUtil.toSetFromJsonArray(eventsJsonfmt, "event");

		int count_lib_in_mymsg = 0;
		Iterator i = set2.iterator();// 先迭代出来

		while (i.hasNext()) {// 遍历
			String renva = (String) i.next();
			if (set.contains(renva))
				count_lib_in_mymsg++;
		}

		Float pipeidu = new Float(count_lib_in_mymsg) / new Float(count)
				* evetnPercent;

		return pipeidu;
	}

	/**
	 * 
	 * @param renvaResult
	 * @param renvas
	 *            [{"num":1,"name":"恋爱男女"},{"num":1,"name":"夫妻关系"}]
	 * @return
	 */

	private Float getRenvaPipeidu(List<Map> renvaResult, String renvas) {
		if (renvaResult.size() == 0)
			return 0f;
		Set set = new HashSet<String>();
		for (Map mp : renvaResult) {
			set.add(mp.get("name"));
		}
		int count = set.size();

		Set set2 = new HashSet<String>();
		JSONArray jsonArray = JSONArray.fromObject(renvas);
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject jo = (JSONObject) jsonArray.get(i);
			set2.add(jo.get("name"));
		}

		int count_lib_in_mymsg = 0;
		Iterator i = set2.iterator();// 先迭代出来

		while (i.hasNext()) {// 遍历
			String renva = (String) i.next();
			if (set.contains(renva))
				count_lib_in_mymsg++;
		}

		Float pipeidu = new Float(count_lib_in_mymsg) / new Float(count)
				* evetnPercent;

		return pipeidu;
	}

	Set set4Cywejon;

	/**
	 * 
	 * @param keyword
	 *            a b c
	 * @return
	 */
	private String getCywejonMysqlFormat(final String[] keyword_arr) {
		
		//o1g  dedulei
		 String[] sa2=	(String[]) new tryX() {
			
			@Override
			public Object item(Object t) throws Exception {
				String[] a=listUtil.deDulicate(keyword_arr);
				return a;
			}
		}.$(keyword_arr);
		
		
		
		if (set4Cywejon == null)
			set4Cywejon = CywejonSet;
		String s = "";
		for (String word : sa2) {
			if (set4Cywejon.contains(word))
				s = s + ">" + word;
			else
				s = s + "<" + word;

		}
		return s;
	}

	static Map CywejonMap;
	static Set CywejonSet;

	/**
	 * CREATE TABLE `word_keyword_quezhon` (
  `word` varchar(255) DEFAULT NULL,
  `quezhonxisho` int(11) DEFAULT NULL,
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `disable` int(11) DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `i_word` (`word`)
) ENGINE=InnoDB AUTO_INCREMENT=15673 DEFAULT CHARSET=utf8;


	 * zafei ini CywejonSet
	 * 
	 * @return
	 */
	public void ini_CywejonSet() {
		if (CywejonMap == null) {

			String sql = "SELECT  *  FROM word_keyword_quezhon  where disable=0  ";
			// sql=sql.replaceAll("@sFentsiFilted", sFentsiFilted);
			System.out.println(sql);

			// if (this.dbc == null)
			// this.dbc = new Dbcontroller();
			CywejonMap = this.dbc.getMap(sql, "word", "quezhonxisho");
			// set = this.dbc.getSet(sql, "单词");

			// cbe
			// List<String> renvaKws =
			// fentsiController_cbb.renvaEventCon.renvaKws;
			// for (String kw : renvaKws) {
			// CywejonMap.put(kw, "3");
			// }
			// List<String> eventKws =
			// fentsiController_cbb.renvaEventCon.eventKws;
			// for (String kw : eventKws) {
			// CywejonMap.put(kw, "3");
			// }
			// cb20
			List<String> renvaKws = WordsLibController.RenvaEventKws;
			for (String kw : renvaKws) {
				CywejonMap.put(kw, "3");
			}

			CywejonSet = CywejonMap.keySet();

		}

		// return set;
	}

	fentsiCa22 fentsiControllerWithDBwordlib;
	String fentsi_filted_per_dbline_ini;

	/**
	 * @since cb4  哎哟不错哦 测试修理
	 * @param s_fentsi
	 * @return
	 */
	private String getFilted(String s_fentsi) {
		// fentsiOr fentsiCca22=new fentsiOr();
		// String s_fentsi_cb4 = fentsiControllor.fentsiByDBwordlib(s_fentsi);

		if (fentsiControllerWithDBwordlib == null)
			fentsiControllerWithDBwordlib = new fentsiCa22();

		String s_fentsi_filted_cb4 = fentsiControllerWithDBwordlib.filtBydb(
				s_fentsi, " ");
		fentsi_filted_per_dbline_ini = s_fentsi_filted_cb4;
		// cb4
//		if (s_fentsi_filted_cb4.trim().split(" ").length <=1) {
//			s_fentsi_filted_cb4 = s_fentsi;
//			// s_fentsi_filted="未来 哪里";
//		}
		
		//o19   哎哟不错哦 测试修理
		if(s_fentsi_filted_cb4.trim().length()==0)
			s_fentsi_filted_cb4=s_fentsi;
		return s_fentsi_filted_cb4;

	}

	/**
	 * @since ca28 *4
	 * @param cinsyv
	 * @return
	 */
	private String cinsyv_ext_sqlfmt(String cinsyv) {
		if (cinsyv.equals("正面"))
			return "'正面','中性'";
		else if (cinsyv.equals("负面"))
			return "'负面','中性'";

		else
			return "'中性'";
	}

	private String cinsyv_ext(String cinsyv) {
		if (cinsyv.equals("正面"))
			return "'正面','中性'";
		else if (cinsyv.equals("负面"))
			return "'负面','中性'";

		else
			return "'中性'";
	}

	
	/**
	 * CREATE TABLE `word_tonyi` (
  `word` mediumtext,
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `i_f` (`word`)
) ENGINE=MyISAM AUTO_INCREMENT=14803 DEFAULT CHARSET=utf8;
	 * @param sFentsiFilted
	 * @return
	 */
	private String extWord(String sFentsiFilted) {
		sFentsiFilted = sFentsiFilted.replaceAll("\\|", " ");
		sFentsiFilted = sFentsiFilted.trim();
		String r = "";
		String sql = "SELECT  *  FROM  word_tonyi  WHERE MATCH (word) AGAINST ( '@sFentsiFilted' )  LIMIT 1000";
		sql = sql.replaceAll("@sFentsiFilted", sFentsiFilted);
		System.out.println(sql);
		Dbcontroller c = new DbNdsController();
		ResultSet rs = c.getrs(sql);
		try {
			while (rs.next()) {
				r = r + "," + rs.getString("word");

			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		c.close();
		r = r.replaceAll(",,", ",");
		r = r.replaceAll(",", " ");
		r = r.trim();
		r = r + "," + sFentsiFilted;
		r = r.replaceAll(",,", ",");
		r = r.replaceAll(",", " ");
		r = r.replaceAll("  ", " ");
		r = listUtil.deDulicate(r, " ");
		return r;
	}

	private String getEvents_SqlParamfmt(List<Map> lievents) {
		String s = "";
		for (Map mp : lievents) {
			String renva = (String) mp.get("event");
			s = s + "," + convetSqlStringFromat(renva);
		}
		s = strUtil.trimx(",", s);
		return s;
	}

	private String getRenva_SqlParamfmt(List<Map> renvaResult) {
		String s = "";
		for (Map mp : renvaResult) {
			String renva = (String) mp.get("name");
			s = s + "," + convetSqlStringFromat(renva);
		}
		s = strUtil.trimx(",", s);
		return s;
	}

	public void indexAll() {
		List li = this.readDBx();
		this.lidb = li;
		this.from = "sincinlib";
		writeToIndex();

		List li_pro = readDB4pro();
		this.lidb = li_pro;
		this.from = "problemlib";
		writeToIndex();

	}

	protected List readDB4pro() {
		return readDB4pro(999999);
	}

	public static String indexBatchID; // cb0

	/**
	 * @since cb3
	 * @return
	 */
	protected List readDB4pro(int limitint) {
		List<Map> li = new ArrayList<Map>();
		// beclseu db is utf8...so length 15=5g hezi
		// and m.id=489879
		String sql = "	SELECT     	m.type,  	m.id,  	m.moodtype AS moodids,  	m.title AS content  FROM  	topic m   LEFT JOIN moodInfo ON m.moodtype = moodInfo.id  WHERE   m.id > (  	SELECT  		iF (max(mid) is null , 0, max(mid)	)  	FROM  		mood4fulllog  	WHERE  		rectype = 'problemlib'  and indexbatchid='@indexbatchid'  )  AND  	char_length(m.title) > 5  AND   verifycount = 1  and visible>0  ORDER BY  	id  LIMIT         "
				+ limitint;
		sql = sql.replaceAll("@indexbatchid", indexBatchID);
		logger.info(sql);
		Dbcontroller dbc_nbta = new DbNdsController();
	//	this.dbc='钱%';
		Dbcontroller dbc_nbt = new DbNdsController();
		ResultSet rs =dbc_nbta.getrs(sql);
		try {
			while (rs.next()) {

				// 首先使用ISO-8859-1字符集将name解码为字节序列并将结果存储新的字节数组中。
				// 然后使用GB2312字符集解码指定的字节数组
				// name = new String(name.getBytes("ISO-8859-1"),"GB2312");

				// 输出结果
				String txt = rs.getString("content");
				Map mp = new HashMap<String, String>();
				mp.put("id", rs.getString("id"));
				// mp.put("userId", rs.getString("userId"));
				String moodids = rs.getString("moodids");
				mp.put("moodid", moodids);
				fulltxtControllor c=new fulltxtControllor(5);
			//	c.dbc=dbc_nbt;
				String moodnames = c.getMoodnamesByids(moodids);
				mp.put("moodname", "纠结");
				mp.put("content", txt);
				// m.id,m.userId,mood,moodInfo.name,m.content
				mp.put("from", "问题库");
				mp.put("renvaids", rs.getString("type"));

				li.add(mp);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);

		}
		dbc_nbta.close();
		dbc_nbt.close();
		return li;
	}

	public static Map sincinSetFromProblmLib;

	
	/**
	 * 
	 * @param moodids ,this.dbc
	 * @return
	 */
	public String getMoodnamesByids(String moodids) {

		if (sincinSetFromProblmLib == null) {
			sincinSetFromProblmLib = new HashMap<String, String>();
			String sql = " select *  from moodInfo  ";
			if(this.dbc==null)
				this.dbc=new DbNdsController();
			sincinSetFromProblmLib = this.dbc.getMap(sql, "id", "name");
			
		}

		String r = "";
		String[] a = moodids.split(",");
		for (String moodid : a) {
			r = r + "," + sincinSetFromProblmLib.get(moodid);
		}
		r = strUtil.trimx(",", r);
		return r;
	}

	fentsiOr fentsiCca22;
	renvaEventC renvaEventCca28;
	protected String mid;

	public void writeToIndex() {
		@SuppressWarnings("unused")
		fileC0 fc = new fileC0();
		List<Map> li1 = lidb;
		int n = 0;
		for (Map mp : li1) {
			n++;
			if (n % 10 == 0)
				System.out.println("--writeToIndex:" + n);
			String line = (String) mp.get("content");

			// ca 28
			if (fentsiCca22 == null)
				fentsiCca22 = new fentsiOr();
			String txtFentsied = fentsiCca22.fentsiByDBwordlib(line);
			if (txtFentsied.length() == 0) // 可能标点符号..走chenlei empty le ..
			{
				continue;
			}
			// //c28 e

			System.out.println("正在建立索引 : " + txtFentsied + "");
			this.id = (String) mp.get("id");

			String[] txtFentsiedArray = txtFentsied.split("\\|");
			if (renvaEventCca28 == null)
				renvaEventCca28 = new renvaEventC();

			// get renva
			if (this.from.equals("problemlib")) {
				String renvaids = (String) mp.get("renvaids");
				this.renvaList = geneRenvaList(renvaids);
				// this.renvaAll = JSONArray.fromObject(renvaResult).toString();
			} else {

				renvaEventCca28.getTypeFromDB(txtFentsiedArray);
				List<Map> renvaResult = renvaEventCca28.TypeResult;
				this.renvaList = renvaEventCca28.TypeResult;
				// this.renva = getrenva(txtFentsied);

			}
			this.renvaAll = JSONArray.fromObject(this.renvaList).toString();

			// get event
			renvaEventC rc = renvaEventCca22;
			@SuppressWarnings("unused")
			List liEvent = renvaEventCca28.getEventsFromDBlib(
					txtFentsiedArray, this.renvaList);
			this.eventAll = JSONArray.fromObject(liEvent).toString();
			this.liEvents = liEvent;

			// //cinsyv
			this.mid = (String) mp.get("id");
			if (this.mid.equals("23763"))
				System.out.println("a");
			String moodnamej = (String) mp.get("moodname");
			moodnamej = convetMoodName2cinsyv_habin(moodnamej);
			String[] mood_arr = moodnamej.split(",");
			for (String mood : mood_arr) {
				this.cinsyv = getcinsyv(mood);

				System.out.println("--cinsyv" + this.cinsyv);
				System.out.println("--event" + this.event);
				txtFentsied = txtFentsied.replaceAll("\\|", " ");
				this.uid = (String) mp.get("userId");
				this.moodid = (String) mp.get("moodid");

				this.moodname = (String) mp.get("moodname");
				// this.curLinenum=i+1;
				writeToIndexSingle(txtFentsied);
			}

			// save jindu
			savejindu(this.mid, this.from);

		}

	}

	protected void savejindu(String mid2, String from2) {
		String sql = "	insert into mood4fulllog(mid,rectype,timex)"
				+ "values(@mid,'@rectype',now())";
		sql = sql.replaceAll("@mid", mid2);
		sql = sql.replaceAll("@rectype", from2);

		// String sql="";
		// if (sqlC == null)
		// exportTopic sqlC = new exportTopic();
		int r = this.dbc.execCb2(sql);

	}

	/**
	 * 
	 * @param moodnamej
	 *            a,b_sincin ,>>> aa,bb(cinsyv)
	 * @return
	 */
	protected String convetMoodName2cinsyv_habin(String moodnamej) {
		if (moodnamej == null || moodnamej.trim().length() == 0)
			return "负面";

		LuceneIndex lic = new LuceneIndex(0);

		String r = "";
		String[] mood_arr = moodnamej.split(",");
		for (String mood : mood_arr) {
			mood = mood.trim();
			String cinsyv = lic.getcinsyv(mood);
			r = r + "," + cinsyv;
		}
		r = strUtil.trimx(",", r);
		r = listUtil.deDulicate(r);
		return r;
	}

	renvaEventC renvaEventCca29;
	Map map4Renva;

	/**
	 * only 4 problem lib
	 * 
	 * @param renvaTypeids
	 * @return
	 */
	protected List<Map> geneRenvaList(String renvaTypeids) {

		List<Map> li = new ArrayList<Map>();
		if (renvaTypeids.equals("")) {
			Map mp = new HashMap<String, String>();
			mp.put("num", "999");
			mp.put("name", "自身烦恼");
			li.add(mp);
			return li;
		}

		inimap4Renva();
		if (renvaEventCca29 == null)
			renvaEventCca29 = new renvaEventC();
		// map4Renva

		String[] a = renvaTypeids.split(",");
		for (String renvaid : a) {
			Map mp = new HashMap<String, String>();
			mp.put("num", "999");
			String renvaGwesyi = (String) map_Renva4problem.get(renvaid);
			String renvaGwesyi_convert2sincinRenvagwesyi = renvaEventCca29
					.conventProblemType2sincinRenvaRelation(renvaGwesyi);

			mp.put("name", renvaGwesyi_convert2sincinRenvagwesyi);

			li.add(mp);
		}
		// String sql="select id,name from topicType where id in (renvaAll2)";
		// if (sqlC == null)
		// sqlC = new exportTopic();
		//		 
		// ResultSet rs= sqlC.getrs(sql);
		// try {
		// while (rs.next()) {
		// Map mp=new HashMap<String, String>();
		// mp.put("num", "999");
		// mp.put("name", rs.getString("name"));
		// li.add(mp);
		// }
		// } catch (SQLException e) {
		// e.printStackTrace();
		// throw new RuntimeException(e);
		// }
		return li;
	}

	public static Map map_Renva4problem;

	/**
	 * only 4 problem renva fenlei
	 */
	protected void inimap4Renva() {
		if (map_Renva4problem == null) {
			map4Renva = new HashMap<String, String>();
			map_Renva4problem = new HashMap<String, String>();
			// map4Renva = inimap4Renva();

			// Map mp = new HashMap<String, String>();
			String sql = "select id,name from topicType ";
			// if (sqlC == null)
			sqlC = new DbNdsController();

			ResultSet rs = sqlC.getrs(sql);
			try {
				while (rs.next()) {

					map4Renva.put(rs.getString("id"), rs.getString("name"));
				}
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
			sqlC.close();
			map_Renva4problem = map4Renva;
		}
	}

	/**
	 * 
	 */
	public List<Map> events_li;
	Dbcontroller sqlC;
	protected String from;

	// exportTopic sqlC;
	// @SuppressWarnings("unchecked")
	/**
	 * event renva for
	 */
	@SuppressWarnings("unchecked")
	protected void writeToIndexSingle(String txtFentsied) {
		int n = 0;
		for (Map mp : this.renvaList) {
			for (Map mp_event : this.events_li) {
				String renva = (String) mp.get("name");

				// Map mpEvent = (Map) this.liEvents.get(n);
				Map mpEvent = mp_event;
				String eventx = (String) mpEvent.get("event");

				String sql = "	insert into mood4full(mid,content,renva,"
						+ "event,cinsyv,renvaAll,eventAll,fromx)"
						+ "values(#{id}, #{content},@renva, @event,@cinsyv,@renvaAll,@eventAll,@from)";

				// sql=sql.replaceAll("#", this.id);
				sql = sql.replaceAll("#\\{id\\}", this.id);
				sql = sql
						.replaceAll("#\\{content\\}", "'" + txtFentsied + "'");
				String convetSqlStringFromatx = convetSqlStringFromat(this.renvaAll);
				sql = sql.replaceAll("@renvaAll", convetSqlStringFromatx);
				sql = sql.replaceAll("@eventAll",
						convetSqlStringFromat(this.eventAll));

				sql = sql.replaceAll("@renva", convetSqlStringFromat(renva));
				sql = sql.replaceAll("@event", convetSqlStringFromat(eventx));
				sql = sql.replaceAll("@cinsyv",
						convetSqlStringFromat(this.cinsyv));
				sql = sql
						.replaceAll("@from", convetSqlStringFromat(this.from));

				System.out.println(sql);

				// return ds;
				int r = this.dbc.execCb2(sql);
				// sqlC.close();
				System.out.println("--exe int:" + r);
				n++;
			}
		}
	}

	public Dbcontroller dbc;
	public boolean AutoCommit = true;
	public static long ini_words_time;
	public long fentsi_mmseg_time;
	public long exe_query_sql_time;
	public int exceptUid;
	public Dbcontroller 数据库控件;
	public boolean onlyPrblm=false;

	protected void setAutoCommit(boolean b) {
		AutoCommit = b;

	}

	protected String convetSqlStringFromat(String renva) {

		return "'" + renva + "'";
	}

}
